<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
    function f(){
            try{
                let x = document.getElementById("demo").value;
            if(x == ""){
                throw("值为空");
            }
            if(isNaN(x)){
                throw("值不是数字");
            }
            }
            catch(err){
               alert("错误："+ err + "。") ;
            }

        }
        window.onload = function(){
            let btn = document.getElementById("btn");
            btn.onclick = function(){
                f();
            }
        }
    </script>

</head>
<body>
    <input type="text" id="demo">
    <button type="button" id="btn" onclick="f">测试输入值</button>
</body>
</html>